package com.yc.db.jdbctemplate;

import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;


@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration("/applicationContext.xml")
public class Test1 {

	@Autowired 
    private JdbcTemplate jdbcTemplate;
	
	@Transactional
	@Test
	public void select() {
		String sql = "select * from t_student where id=4";
		List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
		Map<String, Object> objm = list.get(0);
		System.out.println("name: " + objm.get("name"));
		
		//把查出来的数据写入
		
		
		//拼接sql：
		String sql_i = "insert into t_student(id, name, tel, date) values(14, '" + objm.get("name") + "', '" + objm.get("tel") + "', '" + objm.get("date") + "')";
		jdbcTemplate.execute(sql_i);
		
	}
	
//	@Transactional
//	@Test
//	public void insert() {
//		String sql = "insert into t_student(id, name, tel, date) values(13, 'tom', '1333', '2019-09-09 12:12:12')";
//		jdbcTemplate.execute(sql);
//		
//	}
	
}
